import {defineStore} from 'pinia';
import {useUserStore} from './userStore';


//创建一个仓库
//第一个参数counter要求是一个独一无二的名字
export const useCounterStore = defineStore('counter',{
    //定义仓库状态
    state:()=>({
        count:0,
        age:100,
        name:'hello'
    }),
    getters:{
        doubleCount(state){
            return state.count*2;
        },
        doubleCountPlusOne(){
            return this.doubleCount+1;
        },
        plusAmount(state){
            return (amount)=>{
                return state.count+amount;
            }
        },
        plusFirstName(state){
            const userStore = useUserStore();
            return state.count+userStore.firstName;
        }
    },
    //actions是用来修改store中的状态的方法
    actions:{
        increment(){
            this.count++;
        },
        decrement(){
            this.count--;
        }
    }
});